﻿package mortal.game.view.common.display
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class MoneyInput extends GSprite
    {
        private var _textInput:GTextInput;
        private var _bmp:GBitmap;
        private var _bg:ScaleBitmap;
        private var _minValue:Number;
        private var _maxValue:Number;
        private var _unit:int;
        private var _textInputWidth:int;
        public var checkSelfMoeny:Boolean;

        public function MoneyInput()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._minValue = 0;
            this._maxValue = Number.MAX_VALUE;
            this.checkSelfMoeny = false;
            var _loc_1:* = GlobalStyle.textFormatBai.right();
            this._bg = UIFactory.bg(0, 0, 105, 22, this, ImagesConst.InputBg);
            this._textInput = UIFactory.gTextInput(0, 3, 85, 20, this, "NoSkinInput");
            this._textInput.setStyle("textFormat", _loc_1);
            this._textInput.restrict = "0-9";
            this._bmp = UIFactory.bitmap("", 0, 0, this);
            this.updateMoneyBmpPos();
            this._textInput.configEventListener(Event.CHANGE, this.onTextInputChangeHandler);
            this._textInput.configEventListener(FocusEvent.FOCUS_IN, this.onTextInputFocusInHandler);
            this._textInput.configEventListener(FocusEvent.FOCUS_OUT, this.onTextInputFocusOutHandler);
            return;
        }// end function

        public function set unit(param1:int) : void
        {
            this._unit = param1;
            this._bmp.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this.updateMoneyBmpPos();
            return;
        }// end function

        public function get unit() : int
        {
            return this._unit;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.checkSelfMoeny = false;
            this._minValue = 0;
            this._maxValue = Number.MAX_VALUE;
            this._textInput.text = "";
            this._textInput.restrict = null;
            this._textInput.width = 85;
            this._textInput.dispose(param1);
            this._bg.dispose(param1);
            this._bmp.dispose(param1);
            this._textInput = null;
            this._bg = null;
            this._bmp = null;
            return;
        }// end function

        public function updateMoneyBmpPos() : void
        {
            this._bmp.x = this._bg.x + this._bg.width - this._bmp.width - 3;
            this._bmp.y = this._bg.y + (this._bg.height - this._bmp.height) / 2;
            this._textInput.y = this._bmp.y;
            return;
        }// end function

        protected function onTextInputChangeHandler(event:Event) : void
        {
            this.checkValue();
            return;
        }// end function

        protected function onTextInputFocusInHandler(event:FocusEvent) : void
        {
            return;
        }// end function

        protected function onTextInputFocusOutHandler(event:FocusEvent) : void
        {
            this.checkValue();
            return;
        }// end function

        private function checkValue() : void
        {
            var _loc_1:SMoney = null;
            if (this._textInput == null)
            {
                return;
            }
            if (int(this._textInput.text) > this._maxValue)
            {
                this._textInput.text = this._maxValue.toString();
            }
            else if (int(this._textInput.text) < this._minValue)
            {
                this._textInput.text = this._minValue.toString();
            }
            if (this.checkSelfMoeny)
            {
                _loc_1 = Cache.instance.role.money;
                if (this.unit == EPriceUnit._EPriceUnitCoin && this.value > _loc_1.coin)
                {
                    this._textInput.text = _loc_1.coin.toString();
                }
                else if (this.unit == EPriceUnit._EPriceUnitGold && this.value > _loc_1.gold)
                {
                    this._textInput.text = _loc_1.gold.toString();
                }
                else if (this.unit == EPriceUnit._EPriceUnitCoinBind && this.value > _loc_1.coinBind)
                {
                    this._textInput.text = _loc_1.coinBind.toString();
                }
                else if (this.unit == EPriceUnit._EPriceUnitGoldBind && this.value > _loc_1.goldBind)
                {
                    this._textInput.text = _loc_1.goldBind.toString();
                }
            }
            this._textInput.text = int(this._textInput.text).toString();
            return;
        }// end function

        public function get bmp() : GBitmap
        {
            return this._bmp;
        }// end function

        public function get textInput() : GTextInput
        {
            return this._textInput;
        }// end function

        public function set textInput(param1:GTextInput) : void
        {
            this._textInput = param1;
            return;
        }// end function

        public function get maxValue() : Number
        {
            return this._maxValue;
        }// end function

        public function set maxValue(param1:Number) : void
        {
            this._maxValue = param1;
            return;
        }// end function

        public function get minValue() : Number
        {
            return this._minValue;
        }// end function

        public function set minValue(param1:Number) : void
        {
            this._minValue = param1;
            return;
        }// end function

        public function get value() : Number
        {
            return Number(this._textInput.text);
        }// end function

        public function set value(param1:Number) : void
        {
            this._textInput.text = param1.toString();
            this.checkValue();
            return;
        }// end function

        public function get textInputWidth() : int
        {
            return this._textInputWidth;
        }// end function

        public function set textInputWidth(param1:int) : void
        {
            this._textInputWidth = param1;
            this._textInput.width = this._textInputWidth;
            return;
        }// end function

        public function set defultText(param1:String) : void
        {
            this._textInput.defaultText = param1;
            return;
        }// end function

    }
}
